package org.gou.wicketstudy;

import org.apache.wicket.DefaultPageManagerProvider;
import org.apache.wicket.Page;
import org.apache.wicket.pageStore.IDataStore;
import org.apache.wicket.pageStore.memory.HttpSessionDataStore;
import org.apache.wicket.pageStore.memory.IDataStoreEvictionStrategy;
import org.apache.wicket.pageStore.memory.MemorySizeEvictionStrategy;
import org.apache.wicket.pageStore.memory.PageNumberEvictionStrategy;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.util.lang.Bytes;
import org.gou.wicketstudy.gae.GaeApplication;
import org.gou.wicketstudy.gae.GaeInitializer;
import org.gou.wicketstudy.html.Audio;
import org.gou.wicketstudy.html.SimpleHtml5Audio;

import com.foo.ajax.CalcPage;

public class WicketApplication extends WebApplication implements GaeApplication {
	public Class<? extends Page> getHomePage() {
//		return HomePage.class; 
//		return ConfirmDeletePage.class; // js
//		return CalcPage.class; // ajax
		return Audio.class;
//		return SimpleHtml5Audio.class;
	}
	
	private void mountPages() {
		// mount(new MountedMapperWithoutPageComponentInfo("/", ConfirmDeletePage.class));
	}
	
	@Override
	public void init() {
		mountPages();
		
		new GaeInitializer().init(this);
				
		/*
		 * http://apache-wicket.1842946.n4.nabble.com/Wicket-GAE-td3039886.html
		 */
		getResourceSettings().setResourcePollFrequency(null);
		
		getPageSettings().setVersionPagesByDefault(false);
		
		/* Store data in the HTTP session. */
		this.setPageManagerProvider(new DefaultPageManagerProvider(this) {
			protected IDataStore newDataStore() {
				IDataStoreEvictionStrategy evictionStrategy = new PageNumberEvictionStrategy(3);
				return new HttpSessionDataStore(getPageManagerContext(), evictionStrategy);
			}
		});
		
		
	}

	@Override
	public IDataStoreEvictionStrategy getEvictionStrategy() {
		return new MemorySizeEvictionStrategy(Bytes.megabytes(2));
	}
}